<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="register">
      <form id="bd">
        <p>
          <label>手机号：</label>
          <input
            name="userName"
            type="text"
            id="userName"
            class="txt"
            onblur="checkEmail()"
          />
          <span id="span_email"></span>
        </p>
        <p>
          <label>密码：</label>
          <input
            name="pwd"
            type="password"
            id="pwd"
            class="txt"
            onblur="checkPwd()"
          />
          <span id="span_pwd"></span>
        </p>
        <input type="button" value="提交" id="tj" />
      </form>
    </div>
    <!-- <div>
        <button id="ceshi">测试</button>
    </div> -->
    <script src="../JS/jquery-3.4.1.min.js"></script>
    <script type="text/javascript">
      // $("#ceshi").click(function () {
      //   $.ajax({
      //     method: "get",
      //     url: "/apis/Shopping/api/v1/getAllSlide/",
      //     dataType: "json",
      //     success: function (data) {
      //       console.log(data);
      //     },
      //   });
      // });

      $(function () {
        //   提交按钮
        $("#tj").click(function () {
          if (check()) {
            console.log("通过");
            $.ajax({
              url: "/apis/Shopping/api/v1/login",
              //参数
              data: JSON.stringify({
                userName: $("#userName").val(),
                pwd: $("#pwd").val(),
              }),
              contentType: "application/json",
              //请求类型
              type: "post",
              //响应体类型设置
              dataType: "json",
              //成功回调
              success: function (data) {
                console.log(data);
                window.location.href = "文章管理.html"
              },
              //超时时间
              timeout: 5000,
              //失败回调
              error: function () {
                console.log("出错啦");
              },
              //头信息
              headers: {
                c: 300,
                d: 400,
              },
            });
               // $.ajax({
            //  type: "post",
            //   url: "http://127.0.0.1:8088/Shopping/api/v1/login",
            //   data: {"userName":"15973082888","pwd":123456},
            //   contentType:'json',
            //   dataType: "json",
            //   success: function (data) {
            //     console.log(data);
            //   },
            // });
        //     $.post(
        //   "http://139.198.178.82:9090/Shopping/api/v1/login",
        //   { userName: 100, pwd: 200 },
        //   function (data) {
        //     console.log(data);
        //   }
        // );
          } else {
            //   取消发送表单
            event.preventDefault();
          }
        });
      });
         
      
      function check() {
        if (checkEmail() && checkPwd()) {
          return true;
        }
        return false;
      }
      function checkEmail() {
        var email = $("#userName").val();
        var obj = $("#span_email");
        obj.html("");
        if (email == "") {  
          obj.html("手机号不能为空");
          return false;
        }
       
        return true;
      }
      function checkPwd() {
        var pwd = $("#pwd").val();
        var obj = $("#span_pwd");
        obj.html("");
        if (pwd == "") {
          //使用innerHTML属性设置span标签中的内容
          obj.html("密码不能为空");
          return false;
        }

        return true;
      }
    </script>
  </body>
</html>